﻿@{
    ViewBag.Title = "Test";
    Layout = "~/Areas/Students/Views/Shared/_Layout.cshtml";
}
@section head{
    <link href="~/Content/Test/1.css" rel="stylesheet"/>
}
<div class="am-cf am-padding">
    <div class="am-fl am-cf">
        <strong class="am-text-primary am-text-lg">@ViewBag.testname</strong> / <small>Test</small>
    </div>
</div>

<div class="time-item">


    <strong id="hour_show">0:</strong>
    <strong id="minute_show">00:</strong>
    <strong id="second_show">00</strong>
</div>

@{
    var i = 0;
    foreach (var temp in ViewBag.list)
    {
        i++;
        <div id=" " class="table">
            <form id="@temp.Id" class="form">
                @i、 @temp.Question1
                <br/>
                <input type="radio" name="op" value="A"/> A. @temp.A_op
                <br/>
                <input type="radio" name="op" value="B"/> B. @temp.B_op
                <br/>
                <input type="radio" name="op" value="C"/> C. @temp.C_op
                <br/>
                <input type="radio" name="op" value="D"/> D. @temp.D_op
            </form>
        </div>
    }
}


<div id="submit">
    <input type="button" value="提交试卷" onclick="sub()" class="am-btn am-btn-secondary am-radius" style="margin-top: 20px">
</div>

@section scripts{
    <script type="text/javascript">
        function sub() {
            if (confirm("确认提交？")) {
                Submit();
            }

        }

        function Submit() {
            var x = $(".form");
            x.each(function() {
                var testid = @ViewBag.testid;
                var questid = $(this).attr("id");
                var answer;
                var input = $(this).find("input");
                input.each(function() {
                    if (this.checked)
                        answer = $(this).val();
                });
                $.ajax({
                    url: "/students/index/sub",
                    data: {
                        testid: testid,
                        questid: questid,
                        answer: answer
                    }
                });

            });
            alert("考试结束！随后跳到查看成绩界面");
            window.location.href = "/students/index/GetThisScore/" + @ViewBag.testid;

        }

        var intDiff = parseInt(@ViewBag.time); //倒计时总秒数量
        function timer(intDiff) {
            window.setInterval(function() {
                var day = 0,
                    hour = 0,
                    minute = 0,
                    second = 0; //时间默认值
                if (intDiff > 0) {
                    day = Math.floor(intDiff / (60 * 60 * 24));
                    hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
                    minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
                    second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
                }
                if (hour <= 9) hour = '0' + hour;
                if (minute <= 9) minute = '0' + minute;
                if (second <= 9) second = '0' + second;

                $('#hour_show').html('<s id="h"></s>' + hour + '');
                $('#minute_show').html('<s></s>' + minute + '');
                $('#second_show').html('<s></s>' + second);
                intDiff--;
                if (intDiff == -1) {
                    alert("时间到，考试结束");
                    Submit();
                }

            }, 1000);
        }

        $(function() {
            timer(intDiff);
        });
    </script>
}